package com.pbking.facebook.delegates.data
{
	import com.adobe.serialization.json.JSON;
	import com.pbking.facebook.Facebook;
	import com.pbking.facebook.delegates.FacebookDelegate;
	
	/**
	 * delegate for calling data.updateObject.  
	 * 
	 * reference: http://wiki.developers.facebook.com/index.php/Data.updateObject
	 * 
	 * @author sol wu
	 */
	public class UpdateObjectDelegate extends FacebookDelegate
	{				
		/**
		 * @param properties - Name-value pairs of new properties  
		 * @param replace - True if replace all existing properties; false to merge into existing one
		 */
		public function UpdateObjectDelegate(facebook:Facebook, objid:Number, properties:Object, replace:Boolean)
		{
			super(facebook);
			fbCall.setRequestArgument("obj_id", objid);
			// properties is name-value pair in json format.
			// eg. {"prop1":1,"b":2,"c":3,"d":4,"e":5}
			// in facebook php client, it uses php json_encode() to format an array into it.  
			// eg. fbCall.setRequestArgument("properties", '{"testprop1":"testvalue2","uid":123456789}');
			if (properties) { fbCall.setRequestArgument("properties", JSON.encode(properties));	}
			fbCall.setRequestArgument("replace", replace);
			fbCall.post("facebook.data.updateObject");
		}

	}
}